using System;
using UnityEngine;

namespace Function.SerializedPropertyAttribute
{
    [AttributeUsage(AttributeTargets.Field, Inherited = true, AllowMultiple = false)]
    public class HeadAttribute : PropertyAttribute
    {
        public readonly string _header;

        /// <summary>
        ///   <para>Add a header above some fields in the Inspector.</para>
        /// </summary>
        /// <param name="header">The header text.</param>
        public HeadAttribute(string header) => this._header = header;
    }
}

#if UNITY_EDITOR
namespace Function.SerializedPropertyAttribute
{
    using UnityEditor;

    [CustomPropertyDrawer(typeof(HeadAttribute))]
    public class HeadAttributeDrawer : PropertyDrawer
    {
        private HeadAttribute Attribute =>
            _attribute ??= attribute as HeadAttribute;

        private HeadAttribute _attribute;


        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.PropertyField(position, property, new GUIContent(Attribute._header), true);
        }
    }
}
#endif